/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.center.service.notify;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sinodata.bsm.center.dao.BaseDao;
import com.sinodata.bsm.center.dao.impl.NotifyRuleDaoImpl;
import com.sinodata.bsm.common.vo.NotifyReceiveRule;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author dongyushi
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-7-9 下午6:18:18          dongyushi        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
@Service
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class NotifyReceiveRuleService {
    @Autowired
    private BaseDao baseDao;
    @Autowired
    private NotifyRuleDaoImpl notifyRuleDao;

    @Transactional(propagation = Propagation.REQUIRED)
    public void add(List<NotifyReceiveRule> list) throws Exception {
        baseDao.batchSave(list);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void update(NotifyReceiveRule notifyReceiveRule) {
        baseDao.saveOrUpdate(notifyReceiveRule);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void delete(Long id) {
        notifyRuleDao.deleteNotifyReceiveRuleByNotifyReceiveRuleId(id);
    }

    public boolean validateNotifyReceiveRule(List<NotifyReceiveRule> list, List<NotifyReceiveRule> listAll) {
        boolean flag = true;
        for (NotifyReceiveRule notifyReceiveRule : list) {
            if (listAll != null) {
                for (NotifyReceiveRule nrr : listAll) {
                    if (nrr.getNotifyRuleId().equals(notifyReceiveRule.getNotifyRuleId()) && nrr.getUser().equals(notifyReceiveRule.getUser()) && nrr.getNotifyMode().equals(notifyReceiveRule.getNotifyMode())) {
                        flag = false;
                        break;
                    }
                }
            }
        }
        return flag;
    }
}
